package main

import "fmt"

func f1(f func()) {
	fmt.Println("f1")
	f()
}

func f2(x, y int) {
	fmt.Println("f2")
	fmt.Println(x + y)
}

func f3(f func(int, int), x, y int) func() {
	tmp := func() {
		f(x, y)
	}
	return tmp
}

func calu(base int) (func(int) int, func(int) int) {
	add := func(i int) int {
		base += i
		return base
	}
	sub := func(i int) int {
		base -= i
		return base
	}
	return add, sub
}

func test01(index string, a, b int) int {
	ret := a + b
	fmt.Println(index, a, b, ret)
	return ret
}

func main() {
	//f1(f3(f2, 100, 200))
	//x := 10
	//f4, f5 := calu(x)
	//fmt.Println(f4(1), f5(2))
	//fmt.Println(f4(3), f5(4))
	//fmt.Println(f4(5), f5(6))
	a := 1
	b := 2
	defer test01("1", a, test01("10", a, b)) //10,0,1,1,1,0,1,1
	a = 0
	defer test01("2", a, test01("20", a, b)) //20,0,1,1
	defer func() { fmt.Println(a, b) }()
	//2,0,1,1
	b = 1
}
